import JSEncrypt from "jsencrypt/bin/jsencrypt.min"

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n" +
  "nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=="

const privateKey =
  "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n" +
  "7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n" +
  "PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n" +
  "kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n" +
  "cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n" +
  "DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n" +
  "YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n" +
  "UP8iWi1Qw0Y="

const publicKeyApi =
  "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp9OI9YztTY/muOeMABXRWrGShdneRoFHH4m+1WpN2tzDjuaMsmIXJkSWcs86kupQJw2nEwQCNPFD76u8l/Bh/Uqvvi2/NiSzfIgppwjISyhfrNvYVNK0YWS53d+ukB7W7RXgepk+YfFuF/73FBDy99osh1lOd0VJRDu8g5Vx+O8eXCgqi8T5bEQV0MW8DMKc8ye3PDJvOqYtiz5Gf6RamOfjcV1KC5eS8+wNHJyA7R82EWH7PEMlQFkf4Zj+/KG7RiYNvhqrc+Uq93QC9pR/jduqgtXjobixC+/9XMXvjbQu6eIj694hAUtbWHSv/a5iNq0xZvUP1pnKP6JXOweO3wIDAQAB"

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

export function encryptApi(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKeyApi) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
